package com.imooc.activiti.event;

import com.imooc.activiti.delegate.MdcErrorDelegate;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.delegate.event.ActivitiEventType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author lynn
 * @date 18-12-23 下午9:45
 */
public class ProcessEventListener implements ActivitiEventListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(MdcErrorDelegate.class);


    @Override
    public void onEvent(ActivitiEvent activitiEvent) {
        ActivitiEventType eventType = activitiEvent.getType();

        if(ActivitiEventType.PROCESS_STARTED.equals(eventType)){
            LOGGER.info("流程启动 {} \t {}",eventType,activitiEvent.getProcessInstanceId());
        }

        if(ActivitiEventType.PROCESS_COMPLETED.equals(eventType)){
            LOGGER.info("流程结束 {} \t {}",eventType,activitiEvent.getProcessInstanceId());
        }
    }

    @Override
    public boolean isFailOnException() {
        return false;
    }
}
